using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class DropdownBinder : BinderBase
{
    public enum AttributeType : int
    {
        onValueChanged,
        alphaFadeSpeed,
        value,
        interactable,
        enabled,
    }
    
    private Dropdown _target;
    
    public DropdownBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public DropdownBinder()
    {
        
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<Dropdown>();
        _active = _target != null;
    }
    public override void SetActionInt32(UnityAction<int> action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onValueChanged:
                _target.onValueChanged.AddListener(action);
            break;
            default:
            break;
        }
        base.SetActionInt32(action);
    }
    
    public override void RemoveActionInt32(UnityAction<int> action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onValueChanged:
                _target.onValueChanged.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveActionInt32(action);
    }
    
    public override void SetSingle(float value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.alphaFadeSpeed:
                _target.alphaFadeSpeed = value;
            break;
            default:
            break;
        }
        base.SetSingle(value);
    }
    
    public override void SetInt32(int value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.value:
                _target.value = value;
            break;
            default:
            break;
        }
        base.SetInt32(value);
    }
    
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.interactable:
                _target.interactable = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void RemoveAllAction()
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onValueChanged:
                _target.onValueChanged.RemoveAllListeners();
            break;
            default:
            break;
        }
    }
    
}